<template>
  <div class="summary">
    <div class="summary-left">
      <div class="summary-left-title">产品信息</div>
      <ul class="summary-left-list">
        <li
          :class="{ 'summary-left-list-active': item.isActive }"
          v-for="(item, index) in menuLeft"
          :key="'left_' + index"
          @click="handleMenuLeft(item)"
        >
          {{ item.label }}
        </li>
      </ul>
    </div>
    <div class="summary-content">
      <div class="summary-content-btn mb10 pr30">
        <div v-if="isEdit">
          <el-button @click="handleCancel">取消</el-button>
          <el-button type="primary" @click="handleSubmit">保存</el-button>
        </div>
        <el-button v-else type="primary" @click="editFn" v-auth:agv="'update'">编辑</el-button>
      </div>
      <div class="summary-content-bg">
        <el-scrollbar ref="scrollbarRef" height="calc(100% - 72px)">
          <el-form
            class="pl30 pt30 pr30 pb30"
            ref="ruleFormRef"
            label-suffix=" :"
            :rules="rules"
            :model="formData"
            label-position="top"
            :disabled="!isEdit"
          >
            <component :is="currentActivePage" :form-data="formData" :select-list="selectList" v-bind="ownProps"></component>
          </el-form>
        </el-scrollbar>
      </div>
    </div>
  </div>
</template>
<script lang="ts" setup>
import { onMounted, ref, computed, unref, provide } from "vue"; // computed onUnmounted
import { useRoute } from "vue-router";
import { useData } from "../hooks/useData.ts";
import { useAdd } from "../hooks/useAdd.ts";
import { useEdit } from "../hooks/useEdit.ts";
// import { useUtils } from "../hooks/useUtils";
// import { useDict } from "@/hooks/useDict";
// import mittBus from "@/utils/mittBus";
// content
import Basic from "./content/Basic.vue";
import Key from "./content/Key.vue";
import Assemble from "./content/Assemble.vue";
import TestVideo from "./content/TestVideo.vue";
import Shape from "./content/Shape.vue";
import Doc from "./content/Doc.vue";
import Other from "./content/Other.vue";
// api
// import { getProductDetail } from "@/api/modules/agv";
// import { getListAllUser } from "@/api/modules/sys";
// hook
// const { getDict } = useDict(["appearance", "testVideo"]);
// import { useHandleData } from "@/hooks/useHandleData";
const { formData, rules, ruleFormRef, selectList, appearance, testVideo } = useData();
// 变量
const emits = defineEmits(["refresh"]);
const route = useRoute();
const scrollbarRef = ref(null);
const productId = unref(ref(route.query.id));
const type = unref(ref(route.query.type as string));
// const detail = ref<any>({});
const isEdit = ref(type == 1);
provide("isEdit", isEdit);
provide("selectList", selectList);
// const listAllUser = ref<any>([]);

const { handleSubmit, initData, handleCancel } =
  type == 1
    ? useAdd({ emits, ruleFormRef, formData, selectList, appearance, testVideo, rules })
    : useEdit({ emits, ruleFormRef, formData, id: productId, selectList, appearance, testVideo, isEdit, rules });
const menuLeft = ref([
  {
    label: "基本信息",
    value: 1,
    isActive: true
  },
  {
    label: "关键零件",
    value: 2,
    isActive: false
  },
  {
    label: "车辆外观",
    value: 3,
    isActive: false
  },
  {
    label: "装配信息",
    value: 4,
    isActive: false
  },
  {
    label: "测试视频",
    value: 5,
    isActive: false
  },
  {
    label: "车辆文档",
    value: 6,
    isActive: false
  },
  {
    label: "其他信息",
    value: 7,
    isActive: false
  }
]);
// computed
const currentActivePage = computed(() => {
  scrollbarRef?.value?.setScrollTop(0);
  const obj = menuLeft.value.find((item: any) => item.isActive);
  switch (obj.value) {
    case 1:
      return Basic;
    case 2:
      return Key;
    case 3:
      return Shape;
    case 4:
      return Assemble;
    case 5:
      return TestVideo;
    case 6:
      return Doc;
    case 7:
      return Other;
    default:
      return "";
  }
});
// 动态添加参数
const ownProps = computed(() => {
  const { name } = currentActivePage.value;
  switch (name) {
    case "Shape":
      return { appearance };
    case "TestVideo":
      return { testVideo };
    default:
      return {};
  }
});
// 方法
const editFn = () => {
  isEdit.value = true;
};
const handleMenuLeft = item => {
  menuLeft.value.forEach(itm => {
    itm.isActive = itm.value === item.value;
  });
};
// 获取全部用户
// const getListAllUserFn = async () => {
//   const { data } = await getListAllUser();
//   listAllUser.value = data;
// };

// 获取项目详情
// const getProductDetailFn = async id => {
//   const { data } = await getProductDetail({ id });
//   detail.value = data;
// };

onMounted(() => {
  initData && initData();
});
</script>
<style lang="scss" scoped>
ul,
li,
p {
  padding: 0;
  margin: 0;
  list-style: none;
}
i {
  font-style: normal;
}
.el-select-dropdown__item {
  padding: 0 32px 0 20px;
}
.summary {
  display: flex;
  justify-content: space-between;
  height: 100%;
  .summary-left {
    flex: 0 0 $project-slide-width;
    overflow: hidden;
    background: #ffffff;
    &-title {
      padding: 22px $project-padding-margin;
      font-size: 16px;
      font-weight: 600;
      color: #333333;
    }
    &-list {
      padding: 0 $project-padding-margin;
      li {
        height: 60px;
        margin-top: 20px;
        font-size: 16px;
        font-weight: 600;
        line-height: 60px;
        color: #333333;
        text-indent: $project-padding-margin;
        cursor: pointer;
        background: $project-background;
        border-radius: 6px;
      }
      &-active {
        color: #ffffff !important;
        background: var(--el-color-primary) !important;
      }
    }
  }
  .summary-content {
    display: flex;
    flex: 1;
    flex-flow: column nowrap;
    margin-left: 10px;
    overflow: hidden;
    background: var(--el-bg-color-page);
    &-detail {
      box-sizing: border-box;
      height: 258px;
      padding: 30px;
      background: #ffffff;
      .title {
        margin-bottom: 3px;
        font-size: 16px;
        font-weight: 600;
        color: #333333;
      }
      .info {
        font-size: 14px;
        font-weight: 400;
        color: #999999;
        span {
          margin-right: 30px;
        }
      }
      .options {
        display: flex;
        margin-top: 34px;
        .li {
          display: flex;
          align-items: center;
          margin-right: 114px;
          .flag {
            width: 32px;
            height: 32px;
            margin-right: 10px;
            img {
              width: 100%;
              height: 100%;
              border-radius: 50%;
            }
          }
          .titles {
            display: flex;
            flex-flow: column nowrap;
            i:first-child {
              font-size: 14px;
              font-weight: 400;
              color: #333333;
            }
            i:last-child {
              margin-top: 2px;
              font-size: 12px;
              font-weight: 400;
              color: #999999;
            }
          }
          .calendar {
            display: flex;
            align-items: center;
            justify-content: center;
            width: 32px;
            height: 32px;
            margin-right: 10px;
            font-size: 16px;
            color: #999999;
            border: 1px dashed #cccccc;
            border-radius: 50%;
            svg {
              width: 16px;
              height: 16px;
            }
          }
        }
        .li:hover {
          color: $primary-color;
          .calendar {
            color: $primary-color;
            border: 1px dashed $primary-color;
          }
        }
      }
      .kh-info {
        display: flex;
        flex-flow: column nowrap;
        margin-top: 30px;
        span:first-child {
          margin-bottom: 10px;
          font-size: 14px;
          line-height: 20px;
          color: #999999;
        }
        span:last-child {
          font-size: 16px;
          font-weight: 400;
          color: #333333;
        }
      }
    }
    &-project {
      margin-top: 10px;
      background: #ffffff;
      .project-title {
        box-sizing: border-box;
        display: flex;
        align-items: center;
        justify-content: space-between;
        height: 72px;
        padding: 0 30px;
        span:first-child {
          font-size: 16px;
          font-weight: 600;
          color: #333333;
        }
        span:last-child {
          display: flex;
          align-items: center;
          font-size: 14px;
          font-weight: 600;
          color: #333333;
          cursor: pointer;
          i:first-child {
            width: 15px;
            height: 15px;
            margin-right: 10px;
            font-size: 15px;
            color: #666666;
          }
        }
      }
      .project-content {
        padding: 20px 30px 30px;
        .user-wrap {
          display: flex;
          align-items: center;
          img {
            width: 32px;
            height: 32px;
            margin-right: 10px;
            border-radius: 50%;
          }
          span:last-child {
            font-size: 14px;
            font-weight: 400;
            color: #333333;
          }
        }
      }
      .project-content-wrap {
        padding: 0 30px 20px;
        .project-content-item {
          display: flex;
          flex-flow: column nowrap;
          .title {
            margin-bottom: 10px;
            font-size: 14px;
            font-weight: 400;
            color: #999999;
          }
          .fontWeight {
            font-size: 16px;
          }
          .content {
            margin-bottom: 10px;
            font-size: 14px;
            font-weight: 400;
            color: #333333;
          }
        }
      }
      .empty-box {
        padding: 0 30px 20px;
        font-size: 14px;
        color: var(--el-text-color-secondary);
        text-align: center;
      }
    }
    &-milestone {
      padding: 30px;
      margin-top: 10px;
      background: #ffffff;
      .milestone-title {
        height: 72px;
        margin-bottom: 24px;
        font-size: 16px;
        font-weight: 600;
        line-height: 72px;
        color: #333333;
      }
      .milestone-content {
        position: relative;
        box-sizing: border-box;
        display: flex;
        flex: 1;
        justify-content: center;
        overflow: hidden;
        .milestone-list {
          position: relative;
          display: flex;
          width: max-content;

          // gap: 60px;
          .line-start {
            position: absolute;
            top: 34px;
            left: 0;
            z-index: 2;
            width: 20px;
            height: 20px;
            background: #ffffff;
            i {
              position: absolute;
              top: 50%;
              left: 50%;
              width: 8px;
              height: 8px;
              margin-top: -4px;
              margin-left: -4px;
              border: 1px solid #7499f8;
              border-radius: 50%;
            }
          }
          .line-end {
            position: absolute;
            top: 34px;
            right: -30px;
            z-index: 2;
            width: 20px;
            height: 20px;
            background: #ffffff;
            i {
              position: absolute;
              top: 50%;
              left: 50%;
              width: 8px;
              height: 8px;
              margin-top: -4px;
              margin-left: -4px;
              background: #c7cedb;
              border-radius: 50%;
            }
          }
          li {
            display: flex;
            flex: 0 0 auto;
            flex-flow: column nowrap;
            align-items: center;
            justify-content: center;
            margin-right: 60px;
            span:first-child {
              box-sizing: border-box;
              height: 28px;
              padding: 0 22px;
              margin-bottom: 8px;
              font-size: 14px;
              font-weight: 400;
              line-height: 28px;
              color: #5378f6;
              text-align: center;
              border: 1px solid #5378f6;
              border-radius: 4px;
            }
            .line {
              position: relative;
              width: 100%;
              height: 2px;
              padding: 0 30px;
              margin: 8px 0;
              background: #ededed;
              i:first-child {
                position: absolute;
                top: 50%;
                left: 50%;
                width: 20px;
                height: 20px;
                margin-top: -10px;
                margin-left: -10px;
                background: #ffffff;
              }
              i:last-child {
                position: absolute;
                top: 50%;
                left: 50%;
                box-sizing: border-box;
                width: 8px;
                height: 8px;
                margin-top: -4px;
                margin-left: -4px;
                border: 1px solid #7197f8;
                transform: rotate(45deg);
              }
            }
            span {
              font-size: 14px;
              font-weight: 400;
              color: #5378f6;
              text-align: center;
            }
            span:last-child {
              margin-top: 8px;
            }
          }
          li:nth-child(2) {
            margin-left: 30px;
          }
          .active {
            span:first-child {
              color: rgb(115 216 151);
              border: 1px solid rgb(115 216 151);
            }
            .line {
              i:last-child {
                background: rgb(115 216 151);
                border: 1px solid rgb(115 216 151);
              }
            }
            span {
              color: rgb(115 216 151);
            }
          }
        }
      }
    }
    &-btn {
      display: flex;
      flex: 0 0 72px;
      align-items: center;
      justify-content: flex-end;
      height: 72px;
      background: #ffffff;
    }
    &-bg {
      flex: 1;
      height: 100%;
      background: #ffffff;
    }
  }
}
:deep(.info-form-group) {
  display: flex;
  flex-flow: column nowrap;

  // --el-fill-color-blank: #f7fcfe;
  --el-select-border-color-hover: transparent;
  --el-select-border-color: transparent;
  --el-border-color: transparent;
  --el-input-border-color: transparent;
  --el-fill-color-blank: #f5f7fa;
  .el-upload {
    // var(--input-background)
    background-color: #f5f7fa !important;
  }
  :deep(.d-upload) {
    background-color: #f5f7fa !important;
  }
  .el-select,
  .el-cascader,
  .el-input-number,
  .el-date-editor {
    width: 100%;
    .el-input__inner {
      text-align: left;
    }
  }
  .performanceParameterTable {
    flex: 0 0 142px;
  }
  .other {
    flex: 1;
  }
  .el-form-item--default {
    margin-bottom: 30px;
  }
}
:deep(.info-form-group-title) {
  font-size: 16px;
  font-weight: 600;
  color: #333333;
}
:deep(.info-form-group-content) {
  display: grid;
  column-gap: 40px;
  .custom {
    display: flex;
    flex-flow: column nowrap;
  }
  .custom-image-wrap {
    width: 100%;
    height: 100%;
  }
  .custom-image {
    width: 240px;
    height: 240px;
    background: #f5f7fa;
    .d-upload-add {
      box-sizing: border-box;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 100%;
      height: 100%;
      cursor: pointer;
      background: #f5f7fa;
      &:hover {
        border: 1px dashed $primary-color;
      }
    }
    img {
      width: 100%;
      height: 100%;
      object-fit: contain;
    }
  }
  .upload-text {
    box-sizing: border-box;
    height: 51px;
    padding: 10px;
    background-color: #f5f7fa;
    :deep(.el-textarea__inner) {
      color: #333333;
      background: #ffffff;
    }
  }
  .custom-video {
    display: flex;
    flex-flow: column nowrap;
    justify-content: space-between;
    width: 100%;
    height: 100%;
    background: var(--input-background);
    video {
      width: 100%;
      height: 135px;
      object-fit: contain;
    }
  }
}
:deep(.info-form-group-content-fr2) {
  grid-template-columns: 1fr 3fr;
}
:deep(.info-form-group-content-fr1) {
  display: grid;
  grid-template-columns: 142px auto;
  column-gap: 40px;
}
</style>
